#ifndef SIMPLETCPSERVERDLL_H
#define SIMPLETCPSERVERDLL_H

#include <QObject>
#include <QTcpSocket>
#include <qtcpserver.h>
#include <qtcpsocket.h>
#include <QString>

#include "simpletcpserverdll_global.h"

#define maxSERVERNUMBER 16

typedef struct SimpleTcpClientInfo{
   QByteArray SendData;
   QByteArray RecvData;

   bool switch_send;
   bool switch_receive;

   bool mark_connect;
   bool mark_sendbusy;
   bool mark_ready2read;

}SimpleTcpClientInfo;

typedef struct SimpleTcpSeverInfo{
   int Port;

   bool switch_add;
   bool switch_listen;

   bool mark_used;
   bool mark_listendone;

   int TcpClinetNumber;
   QTcpSocket* pTcpSocket[maxSERVERNUMBER];
   SimpleTcpClientInfo* pSimpleTcpClientInfo[maxSERVERNUMBER];

}SimpleTcpSeverInfo;

class SIMPLETCPSERVERDLLSHARED_EXPORT SimpleTcpServerDLL:QObject{
Q_OBJECT
public:
    int         TcpServerNumber;
    QTcpServer *pTcpServer[maxSERVERNUMBER];
    SimpleTcpSeverInfo *pSimpleTcpSeverInfo[maxSERVERNUMBER];

public:
    SimpleTcpServerDLL();
    ~SimpleTcpServerDLL();

    short SimpleServeradd(const int port, int& order);
    short SimpleServerlisten(const int order);

    short SimpleTcpServerWriteData(const int Order, const int subOrder, QByteArray Data);
    short SimpleTcpServerReadData(const int Order, const int subOrder, QByteArray& Data);

    short SimpleTcpServerConnetedClientNumber(const int order,int& number);

    bool  TcpServerSendBusy(const int Order,const int subOrder);
    bool  TcpServerRead2Read(const int Order,const int subOrder);


    void SimpleServerMainThreadLoopRun(short type);

private:
    short SimpleHasNewClientConnect(int order);

    void SimpleServerMainThreadLoopRun_StateChange();
    void SimpleServerMainThreadLoopRun_Send();
    void SimpleServerMainThreadLoopRun_Receive();
};

#endif // SIMPLETCPSERVERDLL_H
